﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace NotepadExpress
{
    public class GotoForm : Form
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.lineLabel = new System.Windows.Forms.Label();
            this.columnLabel = new System.Windows.Forms.Label();
            this.lineTextBox = new System.Windows.Forms.MaskedTextBox();
            this.columnTextBox = new System.Windows.Forms.MaskedTextBox();
            this.okButton = new System.Windows.Forms.Button();
            this.cancelButton = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // lineLabel
            // 
            this.lineLabel.AutoSize = true;
            this.lineLabel.Location = new System.Drawing.Point(12, 9);
            this.lineLabel.Name = "lineLabel";
            this.lineLabel.Size = new System.Drawing.Size(40, 13);
            this.lineLabel.TabIndex = 0;
            this.lineLabel.Text = "&Line #:";
            // 
            // columnLabel
            // 
            this.columnLabel.AutoSize = true;
            this.columnLabel.Location = new System.Drawing.Point(12, 36);
            this.columnLabel.Name = "columnLabel";
            this.columnLabel.Size = new System.Drawing.Size(55, 13);
            this.columnLabel.TabIndex = 2;
            this.columnLabel.Text = "Col&umn #:";
            // 
            // lineTextBox
            // 
            this.lineTextBox.Location = new System.Drawing.Point(72, 6);
            this.lineTextBox.Mask = "0000000000";
            this.lineTextBox.Name = "lineTextBox";
            this.lineTextBox.PromptChar = ' ';
            this.lineTextBox.Size = new System.Drawing.Size(72, 20);
            this.lineTextBox.TabIndex = 1;
            // 
            // columnTextBox
            // 
            this.columnTextBox.Location = new System.Drawing.Point(72, 32);
            this.columnTextBox.Mask = "0000000000";
            this.columnTextBox.Name = "columnTextBox";
            this.columnTextBox.PromptChar = ' ';
            this.columnTextBox.Size = new System.Drawing.Size(72, 20);
            this.columnTextBox.TabIndex = 3;
            // 
            // okButton
            // 
            this.okButton.Location = new System.Drawing.Point(150, 6);
            this.okButton.Name = "okButton";
            this.okButton.Size = new System.Drawing.Size(75, 23);
            this.okButton.TabIndex = 4;
            this.okButton.Text = "&OK";
            this.okButton.UseVisualStyleBackColor = true;
            this.okButton.Click += new System.EventHandler(this.okButton_Click);
            // 
            // cancelButton
            // 
            this.cancelButton.Location = new System.Drawing.Point(150, 32);
            this.cancelButton.Name = "cancelButton";
            this.cancelButton.Size = new System.Drawing.Size(75, 23);
            this.cancelButton.TabIndex = 5;
            this.cancelButton.Text = "&Cancel";
            this.cancelButton.UseVisualStyleBackColor = true;
            this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
            // 
            // GotoForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(237, 65);
            this.Controls.Add(this.cancelButton);
            this.Controls.Add(this.okButton);
            this.Controls.Add(this.columnTextBox);
            this.Controls.Add(this.lineTextBox);
            this.Controls.Add(this.columnLabel);
            this.Controls.Add(this.lineLabel);
            this.MaximizeBox = false;
            this.Name = "GotoForm";
            this.Text = "Go to...";
            this.Load += new System.EventHandler(this.GotoForm_Load);
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.GotoForm_FormClosing);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label lineLabel;
        private System.Windows.Forms.Label columnLabel;
        private System.Windows.Forms.MaskedTextBox lineTextBox;
        private System.Windows.Forms.MaskedTextBox columnTextBox;
        private System.Windows.Forms.Button okButton;
        private System.Windows.Forms.Button cancelButton;

        private MainForm frm;

        public GotoForm()
        {
            InitializeComponent();
        }

        private void GotoForm_Load(object sender, EventArgs e)
        {
            frm = (MainForm)Application.OpenForms["MainForm"];
            if (frm.LineToGo > 0)
                lineTextBox.Text = frm.LineToGo.ToString();
            if (frm.ColumnToGo > 0)
                columnTextBox.Text = frm.ColumnToGo.ToString();
        }

        private void GotoForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (lineTextBox.Text.Length > 0)
                frm.LineToGo = Convert.ToInt32(lineTextBox.Text);
            if (columnTextBox.Text.Length > 0)
                frm.ColumnToGo = Convert.ToInt32(columnTextBox.Text);
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            Document doc = frm.ActiveDocument();
            if (doc != null)
            {
                int lineToGo = 0, columnToGo = 0;
                if (lineTextBox.Text.Length > 0)
                    lineToGo = Convert.ToInt32(lineTextBox.Text);
                if (columnTextBox.Text.Length > 0)
                    columnToGo = Convert.ToInt32(columnTextBox.Text);
                doc.GoTo(lineToGo, columnToGo);
            }
            Close();
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
